#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<omp.h>

double start, end;

#define NUM_THREADS 4

void main(){
    int n = 20000;
    double average;
    double sum = 0.0;
    double test[20000];
    for (int i = 0; i <= n; i++)
        // 为数组提供数据
    {
        test[i] = rand();
    }
    start = omp_get_wtime();
    omp_set_num_threads(NUM_THREADS);
    // #pragma omp parallel
    

        // max and min
    double max = test[0];
    double min = test[0];
    #pragma omp parallel for reduction(max:max)
    for (int i = 1; i < n; i++)
    {
        if (test[i] >max )
        {
            
            max = test[i];
        }
    }printf("max = %lf\n", max);
    #pragma omp parallel for reduction(min:min)
    for (int j = 1; j < n; j++) 
    {   
        if (test[j] < min)
        {
            min = test[j];
        }
        
    }
    //printf("max:%f\nmin:%f\n",max,min);
    
    
    //average
    #pragma omp parallel for reduction(+:sum)
    for (int k = 0; k < n; k++)
    {
        sum += test[k];
    }

    average = sum/n;
    //printf("average:%f\n",average);

    //std
    double std = 0.0;
    double total = 0.0;
    #pragma omp parallel for reduction(+:total)
    for (int m = 0; m < n; m++)
    {
        total += (test[m] - average)*(test[m] - average);
    }
    
    std = sqrt((double)(total/n)); 
    //printf("std:%f",std);


    end = omp_get_wtime();
    printf("time:%f", end - start);
}
